<?php

use Illuminate\Support\Facades\DB;

function demo(): void
{

}

function encode(array|null $array): ?string
{
    if(is_null($array)) return null;
    return $array ? '<pre>' . json_encode($array, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_HEX_TAG) . '</pre>'
        : null;
}

/**
 * fileIdToUrl
 * @param string|null $fileId
 * @return string|null
 */
function fileIdToUrl(string|null $fileId = null): ?string
{
    if (is_null($fileId)) return $fileId;
    else return '/' . implode('/', [
            substr($fileId, 0, 4),
            substr($fileId, 4, 2),
            substr($fileId, 6, 2),
            substr($fileId, 8, 2),
            substr($fileId, 10),
        ]);
}

/**
 * points
 * @param array|string|null $columns
 * @return array
 */
function points(array|string $columns = null): array
{
    return [
        is_null($columns) ? '*' : $columns,
        DB::raw('st_x(location) as x'),
        DB::raw('st_y(location) as y'),
        DB::raw('st_astext(location) as location')
    ];
}
